﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using CE.Mail;
using CE.Image;
using CE.Global;
using CE.Database;
using CE.User;
using CE.PostCode;
using CE.PersonalAccident;
using CE.Security;
using CE.Provider;
using CE.StreetDirectory;
using CE.Payment;

public partial class personal_accident_proposalforms_etiqa_proposal_form : System.Web.UI.Page
{
    public static Int64 _PAId, _PAMoreId, _UserId, _CXCTypeId, _ProviderId, _AgentId;

    protected void Page_Load(object sender, EventArgs e)
    {
       
        if (Session[CE.Global.General.PAResultId] != null)
        {
            if (Session[General.ProviderCompanyId] == null)
            {
               // Response.Redirect("~/personal-accident/results.aspx");
                BackToResults();
            }

            if (Session[General.ProviderCompanyId].ToString() != "30")
            {
               // Response.Redirect("~/personal-accident/results.aspx");
                BackToResults();
            }
        }
        else
        {
            //Response.Redirect("~/personal-accident/results.aspx");
            BackToResults();
        }

        if (!IsPostBack)
        {
            if (Session[General.AgentId] != null)
            {
                lblAgentName.Text = "Agent Name: " + Session[General.AgentName].ToString();
            }

            if (Session[General.PAResultId] != null)
            {
                LoadPremium();
                LoadCoverInfo();
                EnableChildPanels();
            }
            else
            {
                //Response.Redirect("~/personal-accident/personal-accident.aspx");
                Response.Redirect("~/personal-accident/");
            }

            #region Date

            ddlChildDOB1.StartYear = CE.Global.General.GetUTCDateTime().Year - 18;
            ddlChildDOB1.EndYear = CE.Global.General.GetUTCDateTime().Year;

            ddlChildDOB2.StartYear = CE.Global.General.GetUTCDateTime().Year - 18;
            ddlChildDOB2.EndYear = CE.Global.General.GetUTCDateTime().Year;

            ddlChildDOB3.StartYear = CE.Global.General.GetUTCDateTime().Year - 18;
            ddlChildDOB3.EndYear = CE.Global.General.GetUTCDateTime().Year;

            ddlChildDOB4.StartYear = CE.Global.General.GetUTCDateTime().Year - 18;
            ddlChildDOB4.EndYear = CE.Global.General.GetUTCDateTime().Year;

            ddlChildDOB5.StartYear = CE.Global.General.GetUTCDateTime().Year - 18;
            ddlChildDOB5.EndYear = CE.Global.General.GetUTCDateTime().Year;

            #endregion

            #region Validation Effect

            txtName.Attributes.Add("onblur", "ShowValidationEffectTwo('" + txtName.ClientID + "','" + rfvName.ClientID + "','" + revName.ClientID + "')");
            txtPostCode.Attributes.Add("onblur", "ShowValidationEffectTwo('" + txtPostCode.ClientID + "','" + rfvPostCode.ClientID + "','" + revPostCode.ClientID + "')");
            txtUnit1.Attributes.Add("onblur", "ShowValidationEffect('" + txtUnit1.ClientID + "','" + rfvUnit1.ClientID + "')");
            txtUnit2.Attributes.Add("onblur", "ShowValidationEffect('" + txtUnit2.ClientID + "','" + rfvUnit2.ClientID + "')");
            txtAddress.Attributes.Add("onblur", "ShowValidationEffect('" + txtAddress.ClientID + "','" + rfvAddress.ClientID + "')");        
            txtEmail.Attributes.Add("onblur", "ShowValidationEffectTwo('" + txtEmail.ClientID + "','" + rfvEmail.ClientID + "','" + revEmail.ClientID + "')");

            txtSpouseName.Attributes.Add("onblur", "ShowValidationEffectTwo('" + txtSpouseName.ClientID + "','" + rfvSpouseName.ClientID + "','" + revSpouseName.ClientID + "')");
            txtChildName1.Attributes.Add("onblur", "ShowValidationEffectTwo('" + txtChildName1.ClientID + "','" + rfvChildName1.ClientID + "','" + revChildName1.ClientID + "')");
            txtChildName2.Attributes.Add("onblur", "ShowValidationEffectTwo('" + txtChildName2.ClientID + "','" + rfvChildName2.ClientID + "','" + revChildName2.ClientID + "')");
            txtChildName3.Attributes.Add("onblur", "ShowValidationEffectTwo('" + txtChildName3.ClientID + "','" + rfvChildName3.ClientID + "','" + revChildName3.ClientID + "')");
            txtChildName4.Attributes.Add("onblur", "ShowValidationEffectTwo('" + txtChildName4.ClientID + "','" + rfvChildName4.ClientID + "','" + revChildName4.ClientID + "')");
            txtChildName5.Attributes.Add("onblur", "ShowValidationEffectTwo('" + txtChildName5.ClientID + "','" + rfvChildName5.ClientID + "','" + revChildName5.ClientID + "')");

            rdoYesHazadousHobby.Attributes.Add("onblur", "CheckHazadousHobbyValidationCss();");
            rdoNoHazadousHobby.Attributes.Add("onblur", "CheckHazadousHobbyValidationCss();");
            rdoYesPhysicaldefect.Attributes.Add("onblur", "CheckPhysicaldefectValidationCss();");
            rdoNoPhysicaldefect.Attributes.Add("onblur", "CheckPhysicaldefectValidationCss();");
            rdoYesInsuranceCancelled.Attributes.Add("onblur", "CheckInsuranceCancelledValidationCss();");
            rdoNoInsuranceCancelled.Attributes.Add("onblur", "CheckInsuranceCancelledValidationCss();");

            #endregion

            Session[General.ViewedDetailsId] = LogUserViewedHistory().ToString();

            if (Session[General.UserId] != null)
            {
                ShowUserDetails();
            }
            else if (Session[General.PAPersonnelId] != null
                && Session[General.PAEmail] != null
                && Session[General.PAPhoneNo] != null
                && Session[General.PAUserName] != null)
            {
                txtName.Text = Session[General.PAUserName].ToString();
                txtMobileNo.PhoneNo = Session[General.PAPhoneNo].ToString();
                txtEmail.Text = Session[General.PAEmail].ToString();
            }
        }
        if (rdoYesHazadousHobby.Checked || rdoNoHazadousHobby.Checked) txtHazadousHobby.Text = "1";
        if (rdoYesPhysicaldefect.Checked || rdoNoPhysicaldefect.Checked) txtPhysicaldefect.Text = "1";        
        if (rdoYesInsuranceCancelled.Checked || rdoNoInsuranceCancelled.Checked) txtInsuranceCancelled.Text = "1";
    }

    private void BackToResults()
    {
        if (Request.QueryString["pid"] != null)
        {
            if (Request.QueryString["pid"].ToString() != "")
            {
                Response.Redirect("~/personal-accident/results.aspx?pid=" + Request.QueryString["pid"].ToString());
            }
            else
            {
                Response.Redirect("~/personal-accident/results.aspx");
            }
        }
        else
        {
            Response.Redirect("~/personal-accident/results.aspx");
        }
    }

    protected void imgbtnBackTop_Click(object sender, ImageClickEventArgs e)
    {
        BackToResults();
    }

    protected void ibtnBack_Click(object sender, ImageClickEventArgs e)
    {
        //Response.Redirect("~/personal-accident/results.aspx");
        BackToResults();
    }

    protected void ibtPostCode_Click(object sender, ImageClickEventArgs e)
    {
        GetPostCode();
    }

    protected void ibtSubmit_Click(object sender, ImageClickEventArgs e)
    {
        if (Session[CE.Global.General.PAResultId] != null)
        {
            if (Session[General.ProviderCompanyId].ToString() != "30")
            {
                //Response.Redirect("~/personal-accident/results.aspx");
                BackToResults();
            }
        }
        else
        {
            //Response.Redirect("~/personal-accident/results.aspx");
            BackToResults();
        }
        CheckValidation();
        ChangeValidationEffectServerSide("proposal");
        if (IsValid)
        {
            Int64 _proposalresult = 0;
            Int64 _childresult = 0;
            EtiqaProposal _etiqaproposal = new EtiqaProposal();
            EtiqaProposalDB _etiqaproposaldb = new EtiqaProposalDB();

            if (Session[General.PAProposalId] != null)
            {
                _etiqaproposal.PAProposalId = Convert.ToInt64(Session[General.PAProposalId].ToString());
            }
            else
            {
                _etiqaproposal.PAProposalId = 0;
            }
            _etiqaproposal.PAId = Convert.ToInt64(Session[General.PAId].ToString());
            _etiqaproposal.PACompanyId = Convert.ToInt64(lblCompanyId.Text.ToString());
            _etiqaproposal.PAInsId = Convert.ToInt64(Session[General.PAResultId].ToString());
            _etiqaproposal.Name = txtName.Text.ToUpper();
            _etiqaproposal.PostalCode = txtPostCode.Text.Trim();
            _etiqaproposal.UnitNo = txtUnit1.Text.Trim();
            _etiqaproposal.HomeNo = txtUnit2.Text.Trim();
            _etiqaproposal.Address = txtAddress.Text.Trim();
            _etiqaproposal.Gender = ddlGender.GetGender();
            _etiqaproposal.NRICNo = ddlIdNumber.GetIdNumber();
            _etiqaproposal.Nationality = ddlNationality.GetNationality();
            _etiqaproposal.MobileNo = txtMobileNo.GetPhoneNo();
            _etiqaproposal.HomePhoneNo = txtHomePhoneNo.GetPhoneNo();
            _etiqaproposal.OfficePhoneNo = txtOfficePhoneNo.GetPhoneNo();
            _etiqaproposal.Email = txtEmail.Text.Trim();
            _etiqaproposal.SpouseName = txtSpouseName.Text.ToUpper();
            _etiqaproposal.SpouseGender = SpouseGender(ddlGender.GetGender()); //ddlSpouseGender.GetGender();
            _etiqaproposal.SpouseNRICNo = ddlSpouseIdNumber.GetIdNumber();
            _etiqaproposal.HasPhysicalDefects = rdoYesPhysicaldefect.Checked;
            _etiqaproposal.PhysicalDefects = txtPhysicaldefectReason.Text.Trim();
            _etiqaproposal.HasEngagedSportsActivities = rdoYesHazadousHobby.Checked;
            _etiqaproposal.EngagedSportsActivities = txtHazadousHobbyReason.Text.Trim();        
            _etiqaproposal.HasInsuranceCancelled = rdoYesInsuranceCancelled.Checked;
            _etiqaproposal.InsuranceCancelledDetails = txtInsuranceCancelledReason.Text.Trim();
            _etiqaproposal.PaymentType = "CreditCard";

            string convertno = General.GetRefNumber(Convert.ToInt64(Session[General.PAId].ToString()));
        
            _etiqaproposal.QuoteRefNo = "PAQ" + convertno.ToString();
            _etiqaproposal.PaymentStatus = false;

            string _totalPaymentAmount = "";
            _totalPaymentAmount = lblAnnualPremium.Text;

            string _paymentOrderNo = "";
            string val = GetOrderNumber();
            string[] _orderno = val.Split(',');
            _etiqaproposal.OrderNo = _orderno[0].ToString();
            _paymentOrderNo = _orderno[0].ToString();
            _etiqaproposal.OrderSerialNo = Convert.ToInt64(_orderno[1].ToString());


            if (Session[CE.Global.General.UserId] != null)
            {
                _etiqaproposal.RefCEUserId = Convert.ToInt64(Session[CE.Global.General.UserId].ToString());
            }
            else if (Session[CE.Global.General.PAPersonnelId] != null)
            {
                _etiqaproposal.RefCEUserId = Convert.ToInt64(Session[CE.Global.General.PAPersonnelId].ToString());
            }

            if (Session[General.AgentId] != null)
            {
                _AgentId = Convert.ToInt64(Session[General.AgentId].ToString());
            }
            else
            {
                _AgentId = 0;
            }
            _etiqaproposal.NInfo1 = _AgentId;
            _etiqaproposal.ViewedDetailId = Convert.ToInt64(Session[General.ViewedDetailsId].ToString());
            _etiqaproposal.Status = true;

            _proposalresult = _etiqaproposaldb.Insert(_etiqaproposal);
            Session[General.PAProposalId] = _proposalresult;
            if (_proposalresult > 0)
            {
                    if (txtCHCount.Text.Trim() != "0")
                    {
                        if (!SaveChildInfo(_proposalresult))
                        {
                            lblMessage.Text = "Child details failed to save!";
                        }
                        else
                        {
                            _childresult = 1;
                        }
                    }
                    else
                    {
                        _childresult = 1;
                    }
                    if (_childresult > 0)
                    {
                        
                        General.ClearAllSession(this.Page, "ALL");
                        //Response.Redirect("~/etiqa/paymentmsg.aspx?ordernumber=" + _paymentOrderNo + "&amount=" + _totalPaymentAmount + "&authresp=OK"
                        //    + "&email=" + txtEmail.Text + "&authcode=1&authdt=1&cctref=1");
                        //Response.Redirect("../etiqa/paymentmsg.aspx?hcrn=" + _paymentOrderNo + "&hcpa=" + _totalPaymentAmount + "&c=1");
                        //Response.Redirect("../etiqa/etiqa_payment.html?hcrn=" + _paymentOrderNo + "&hcpa=" + _totalPaymentAmount + "&c=1");
                        
                        Response.Redirect("https://nera.i2pay.com.sg/etiqa/etiqa_payment.html?hcrn=" + _paymentOrderNo + "&hcpa=" + _totalPaymentAmount + "&c=1");
                    }
               
            }
        }
    }

    protected void txtPostCode_TextChanged(object sender, EventArgs e)
    {
        GetPostCode();
    }

    protected void ddlAddressList_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (ddlAddressList.Items.Count > 0 && ddlAddressList.SelectedIndex >= 0)
        {
            txtAddress.Text = ddlAddressList.Text;
        }
    }

    public string Encode(string sData)
    {
        byte[] encData_byte = new byte[sData.Length];
        encData_byte = System.Text.Encoding.UTF8.GetBytes(sData);
        string encodedData = Convert.ToBase64String(encData_byte);
        return encodedData;
    }

    private void LoadPremium()
    {
        MyDatabase _db = new MyDatabase();
        string strSql = "";
        strSql = @"SELECT CompanyName,PlanName,TotalAnnualPremium,CAST(AnnualPremiumwithGST AS NUMERIC(10,2)) AS AnnualPremiumwithGST,BenefitName,PolicyType,PACompanyId FROM tblProviderPACompareBenefits, ";
        strSql = strSql + " tblProviderCompany WHERE ProviderCompanyId = PACompanyId AND PAInsId = " + Session[CE.Global.General.PAResultId].ToString();
        DataTable _dtResult = new DataTable();
        _dtResult = _db.GetDataTable(strSql);
        if (_dtResult.Rows.Count > 0)
        {
            lblProvider.Text = _dtResult.Rows[0]["CompanyName"].ToString();
            lblPlanName.Text = _dtResult.Rows[0]["PlanName"].ToString();
            //lblAnnualPremium.Text = _dtResult.Rows[0]["AnnualPremiumwithGST"].ToString();
            lblCompanyId.Text = _dtResult.Rows[0]["PACompanyId"].ToString();
            string _policy = _dtResult.Rows[0]["PolicyType"].ToString();
            if (_policy == "IND")
            {
                lblPolicyType.Text = "Individual";
                txtPolicyType.Text = "Individual";
            }
            else if (_policy == "INDSP")
            {
                lblPolicyType.Text = "Individual & Spouse";
                txtPolicyType.Text = "Individual & Spouse";
            }
            else if (_policy == "INDCHD")
            {
                lblPolicyType.Text = "Individual & Children";
                txtPolicyType.Text = "Individual & Children";
            }
            else if (_policy == "INDSPCHD")
            {
                lblPolicyType.Text = "Individual, Spouse & Children";
                txtPolicyType.Text = "Individual, Spouse & Children";
            }

            MyDatabase _db1 = new MyDatabase();
            string strSql1 = "";
            strSql1 = @"SELECT CAST(AnnualPremium AS NUMERIC(10,2)) AS AnnualPremiumwithGST FROM tblPAInsuranceSelectItem WHERE PAId = " + Session[CE.Global.General.PAId].ToString(); ;
            DataTable _dtResult1 = new DataTable();
            _dtResult1 = _db1.GetDataTable(strSql1);
            if (_dtResult1.Rows.Count > 0)
            {
                lblAnnualPremium.Text = _dtResult1.Rows[0]["AnnualPremiumwithGST"].ToString();
            }
        }
        else
        {
            lblProvider.Text = "";
            lblPlanName.Text = "";
            lblAnnualPremium.Text = "";
            lblCompanyId.Text = "0";
            lblPolicyType.Text = "";
            txtPolicyType.Text = "";
        }
    }

    private void LoadCoverInfo()
    {
        MyDatabase _db = new MyDatabase();
        string strSql = "";
        strSql = @"SELECT CoverType, NoOfChild FROM tblPAInsurance WHERE PAID =  " + Session[CE.Global.General.PAId].ToString(); ;
        DataTable _dtResult = new DataTable();
        _dtResult = _db.GetDataTable(strSql);
        if (_dtResult.Rows.Count > 0)
        {
            txtIsCover.Text = _dtResult.Rows[0]["CoverType"].ToString();
            if (_dtResult.Rows[0]["CoverType"].ToString() == "INDCHD" || _dtResult.Rows[0]["CoverType"].ToString() == "INDSPCHD")
            {
                txtCHCount.Text = _dtResult.Rows[0]["NoOfChild"].ToString();
            }
            else
            {
                txtCHCount.Text = "0";
            }
        }
        else
        {
            txtIsCover.Text = "IND";
            txtCHCount.Text = "0";
        }
    }

    private Int64 LogUserViewedHistory()
    {
        UserViewHistoryDB _userviewdb = new UserViewHistoryDB();
        return _userviewdb.LogViewedHistory("PA", Request, "Personal Accident Etiqa proposal form.");
    }

    private bool SaveChildInfo(Int64 PAProposalId)
    {
        bool _result = false;
        ChildInfo _childinfo = new ChildInfo();
        ChildInfoDB _childinfodb = new ChildInfoDB();

        if (txtCHCount.Text.Trim() != "0")
        {
            int _childcount = Convert.ToInt32(txtCHCount.Text.Trim());
            int _insertcount = 0;

            for (int i = 1; i <= _childcount; i++)
            {
                _childinfo.PAChildId = 0;
                _childinfo.PAProposalId = PAProposalId;
                _childinfo.PAId = Convert.ToInt64(Session[CE.Global.General.PAId].ToString());
                _childinfo.PACompanyId = 30;
                if (Session[CE.Global.General.UserId] != null)
                {
                    _childinfo.RefCEUserId = Convert.ToInt64(Session[CE.Global.General.UserId].ToString());
                }
                else
                {
                    _childinfo.RefCEUserId = 0;
                }
                _childinfo.ViewedDetailId = Convert.ToInt64(Session[General.ViewedDetailsId].ToString());
                _childinfo.Status = true;
                if (i == 1)
                {
                    _childinfo.Name = Server.HtmlEncode(General.ClearScriptTag(txtChildName1.Text.ToUpper()));
                    _childinfo.DOB = ddlChildDOB1.GetDate();
                    _childinfo.Gender = Convert.ToChar(ddlChildGender1.GetGender());
                    _childinfo.NRICNo = ddlChildIdNumber1.GetIdNumber();
                    //_childinfo.Nationality = ddlChildNationality1.GetNationality();
                    _childinfo.Relation = ChildRealtion(_childinfo.Gender);
                }
                else if (i == 2)
                {
                    _childinfo.Name = Server.HtmlEncode(General.ClearScriptTag(txtChildName2.Text.ToUpper()));
                    _childinfo.DOB = ddlChildDOB2.GetDate();
                    _childinfo.Gender = Convert.ToChar(ddlChildGender2.GetGender());
                    _childinfo.NRICNo = ddlChildIdNumber2.GetIdNumber();
                    //_childinfo.Nationality = ddlChildNationality2.GetNationality();
                    _childinfo.Relation = ChildRealtion(_childinfo.Gender);
                }
                else if (i == 3)
                {
                    _childinfo.Name = Server.HtmlEncode(General.ClearScriptTag(txtChildName3.Text.ToUpper()));
                    _childinfo.DOB = ddlChildDOB3.GetDate();
                    _childinfo.Gender = Convert.ToChar(ddlChildGender3.GetGender());
                    _childinfo.NRICNo = ddlChildIdNumber3.GetIdNumber();
                    //_childinfo.Nationality = ddlChildNationality3.GetNationality();
                    _childinfo.Relation = ChildRealtion(_childinfo.Gender);
                }
                else if (i == 4)
                {
                    _childinfo.Name = Server.HtmlEncode(General.ClearScriptTag(txtChildName4.Text.ToUpper()));
                    _childinfo.DOB = ddlChildDOB4.GetDate();
                    _childinfo.Gender = Convert.ToChar(ddlChildGender4.GetGender());
                    _childinfo.NRICNo = ddlChildIdNumber4.GetIdNumber();
                    //_childinfo.Nationality = ddlChildNationality4.GetNationality();
                    _childinfo.Relation = ChildRealtion(_childinfo.Gender);
                }
                else if (i == 5)
                {
                    _childinfo.Name = Server.HtmlEncode(General.ClearScriptTag(txtChildName5.Text.ToUpper()));
                    _childinfo.DOB = ddlChildDOB5.GetDate();
                    _childinfo.Gender = Convert.ToChar(ddlChildGender5.GetGender());
                    _childinfo.NRICNo = ddlChildIdNumber5.GetIdNumber();
                    //_childinfo.Nationality = ddlChildNationality5.GetNationality();
                    _childinfo.Relation = ChildRealtion(_childinfo.Gender);
                }

                if (_childinfodb.Insert(_childinfo) > 0)
                {
                    _insertcount++;
                    _result = true;
                }
            }
            _childinfodb = null;
            _childinfo = null;
        }
        return _result;
    }

    public string SpouseGender(string Gender)
    {
        string SGender = "M";
        if (Gender == "M")
        {
            SGender = "F";
        }
        else if (Gender == "F")
        {
            SGender = "M";
        }
        return SGender;
    }

    public string ChildRealtion(char Gender)
    {
        string Relation = "";
        if (Gender == 'M')
        {
            Relation = "Son";
        }
        else if (Gender == 'F')
        {
            Relation = "Daughter";
        }
        return Relation;
    }

    private void CheckValidation()
    {
        txtName.Text = General.ClearScriptTag(txtName.Text);
        txtPostCode.Text = General.ClearScriptTag(txtPostCode.Text);
        txtUnit1.Text = General.ClearScriptTag(txtUnit1.Text);
        txtUnit2.Text = General.ClearScriptTag(txtUnit2.Text);
        txtAddress.Text = General.ClearScriptTag(txtAddress.Text);
        //txtCompanyROCNo.Text = General.ClearScriptTag(txtCompanyROCNo.Text);
        txtSpouseName.Text = General.ClearScriptTag(txtSpouseName.Text);
        txtChildName1.Text = General.ClearScriptTag(txtChildName1.Text);
        txtChildName2.Text = General.ClearScriptTag(txtChildName2.Text);
        txtChildName3.Text = General.ClearScriptTag(txtChildName3.Text);
        txtChildName4.Text = General.ClearScriptTag(txtChildName4.Text);
        txtChildName5.Text = General.ClearScriptTag(txtChildName5.Text);      
        txtHazadousHobbyReason.Text = General.ClearScriptTag(txtHazadousHobbyReason.Text);
        txtPhysicaldefectReason.Text = General.ClearScriptTag(txtPhysicaldefectReason.Text);
        txtInsuranceCancelledReason.Text = General.ClearScriptTag(txtInsuranceCancelledReason.Text);
             
        #region Hazadous Hobby
        if (rdoYesHazadousHobby.Checked)
        {
            rfvHazadousHobbyReason.Enabled = true;

        }
        else
        {
            rfvHazadousHobbyReason.Enabled = false;
        }
        #endregion

        #region Physical defect
        if (rdoYesPhysicaldefect.Checked)
        {
            rfvPhysicaldefectReason.Enabled = true;
        }
        else
        {
            rfvPhysicaldefectReason.Enabled = false;
        }
        #endregion

        #region Insurance Cancelled
        if (rdoYesInsuranceCancelled.Checked)
        {
            rfvInsuranceCancelledReason.Enabled = true;
        }
        else
        {
            rfvInsuranceCancelledReason.Enabled = false;
        }
        #endregion

    }

    private void ProposalNotification()
    {
        string _strSql, _providerName, _providerEmail, _providerCCEmail, _providerBCCEmail, _Date, _Time, _InsuranceName, _RefNo;
        MyDatabase _db = new MyDatabase();
        DataTable _dtProvider = new DataTable();
        DataTable _dtInsurance = new DataTable();
        _Date = "";
        _Time = "";
        _RefNo = "";
        _strSql = "";
        _providerName = "";
        _providerEmail = "";
        _providerCCEmail = "";
        _providerBCCEmail = "";
        _InsuranceName = "Personal Accident Insurance";
        _strSql = "SELECT [CompanyName], [Email1] FROM tblProviderCompany WHERE ProviderCompanyId = 30";
        _dtProvider = _db.GetDataTable(_strSql);
        if (_dtProvider.Rows.Count > 0)
        {
            _providerName = _dtProvider.Rows[0]["CompanyName"].ToString();
            //_providerEmail = _dtProvider.Rows[0]["Email1"].ToString();
            //_providerEmail = CE.Configuration.MyConfigurationManager.GetAppSettingValue("ProposalNotificationReceiver");
        }

        _providerEmail = CE.Configuration.MyConfigurationManager.GetAppSettingValue("EtiqaPA_TO");
        _providerCCEmail = CE.Configuration.MyConfigurationManager.GetAppSettingValue("EtiqaPA_CC");
        _providerBCCEmail = CE.Configuration.MyConfigurationManager.GetAppSettingValue("EtiqaPA_BCC");

        _strSql = "";
        _strSql = "SELECT CONVERT(VARCHAR,ModifiedDate,103) AS [Date], CONVERT(VARCHAR,ModifiedDate,108) AS [Time] ";
        _strSql += " FROM  tblPAProposal_Etiqa WHERE PAId = " + Session[General.PAId].ToString() + " ORDER BY ModifiedDate DESC";
        _dtInsurance = _db.GetDataTable(_strSql);
        if (_dtInsurance.Rows.Count > 0)
        {
            _Date = _dtInsurance.Rows[0]["Date"].ToString();
            _Time = _dtInsurance.Rows[0]["Time"].ToString();
        }
        //_RefNo = General.GetRefNumber("PA", _Date, Session[General.PAId].ToString());
        string convertno = General.GetRefNumber(Convert.ToInt64(Session[General.PAId].ToString()));
        _RefNo = "PAQ" + convertno.ToString();

        if ((_dtProvider.Rows.Count > 0) && (_dtInsurance.Rows.Count > 0))
        {
            MyMailManager.SendProposalCompleteNotification(_providerName, _providerEmail, _providerCCEmail, _providerBCCEmail, _InsuranceName, _Date, _Time, _RefNo);
        }

    }

    private void ChangeValidationEffectServerSide(string strValidationGroup)
    {
        #region Proposal Details
        //Salutation
        //ddlSalutation.ChangeValidationEffectServerSide(strValidationGroup);
        //Name
        if (rfvName.Enabled && rfvName.ValidationGroup == strValidationGroup)
        {
            rfvName.Validate();
            if (rfvName.IsValid == false)
            {
                txtName.ControlStyle.CssClass = "validationError";
            }
            else
            {
                txtName.ControlStyle.CssClass = "";
            }
        }
        else
        {
            txtName.ControlStyle.CssClass = "";
        }

        if (revName.Enabled && revName.ValidationGroup == strValidationGroup)
        {
            if (rfvName.IsValid)
            {
                revName.Validate();
                if (revName.IsValid == false)
                {
                    txtName.ControlStyle.CssClass = "validationError";
                }
                else
                {
                    txtName.ControlStyle.CssClass = "";
                }
            }
        }
        else
        {
            txtName.ControlStyle.CssClass = "";
        }
        //Postal Code
        if (rfvPostCode.Enabled && rfvPostCode.ValidationGroup == strValidationGroup)
        {
            rfvPostCode.Validate();
            if (rfvPostCode.IsValid == false)
            {
                txtPostCode.ControlStyle.CssClass = "validationError";
            }
            else
            {
                txtPostCode.ControlStyle.CssClass = "";
            }
        }
        else
        {
            txtPostCode.ControlStyle.CssClass = "";
        }

        if (revPostCode.Enabled && revPostCode.ValidationGroup == strValidationGroup)
        {
            if (rfvPostCode.IsValid)
            {
                revPostCode.Validate();
                if (revPostCode.IsValid == false)
                {
                    txtPostCode.ControlStyle.CssClass = "validationError";
                }
                else
                {
                    txtPostCode.ControlStyle.CssClass = "";
                }
            }
        }
        else
        {
            txtPostCode.ControlStyle.CssClass = "";
        }

        //Unit No
        if (rfvUnit1.Enabled && rfvUnit1.ValidationGroup == strValidationGroup)
        {
            rfvUnit1.Validate();
            if (rfvUnit1.IsValid == false)
            {
                txtUnit1.ControlStyle.CssClass = "validationError";
            }
            else
            {
                txtUnit1.ControlStyle.CssClass = "";
            }
        }
        else
        {
            txtUnit1.ControlStyle.CssClass = "";
        }

        //Home No
        if (rfvUnit2.Enabled && rfvUnit2.ValidationGroup == strValidationGroup)
        {
            rfvUnit2.Validate();
            if (rfvUnit2.IsValid == false)
            {
                txtUnit2.ControlStyle.CssClass = "validationError";
            }
            else
            {
                txtUnit2.ControlStyle.CssClass = "";
            }
        }
        else
        {
            txtUnit2.ControlStyle.CssClass = "";
        }

        //Address
        if (rfvAddress.Enabled && rfvAddress.ValidationGroup == strValidationGroup)
        {
            rfvAddress.Validate();
            if (rfvAddress.IsValid == false)
            {
                txtAddress.ControlStyle.CssClass = "validationError";
            }
            else
            {
                txtAddress.ControlStyle.CssClass = "";
            }
        }
        else
        {
            txtAddress.ControlStyle.CssClass = "";
        }


        //Gender
        ddlGender.ChangeValidationEffectServerSide(strValidationGroup);

        //Id Number
        ddlIdNumber.ChangeValidationEffectServerSide(strValidationGroup);
        //Nationality
        ddlNationality.ChangeValidationEffectServerSide(strValidationGroup);
        //Mobile Number
        txtMobileNo.ChangeValidationEffectServerSide(strValidationGroup);

        if (rfvEmail.Enabled && rfvEmail.ValidationGroup == strValidationGroup)
        {
            rfvEmail.Validate();
            if (rfvEmail.IsValid == false)
            {
                txtEmail.ControlStyle.CssClass = "validationError";
            }
            else
            {
                txtEmail.ControlStyle.CssClass = "";
            }
        }
        else
        {
            txtEmail.ControlStyle.CssClass = "";
        }

        if (revEmail.Enabled && revEmail.ValidationGroup == strValidationGroup)
        {
            if (rfvEmail.IsValid)
            {
                revEmail.Validate();
                if (revEmail.IsValid == false)
                {
                    txtEmail.ControlStyle.CssClass = "validationError";
                }
                else
                {
                    txtEmail.ControlStyle.CssClass = "";
                }
            }
        }
        else
        {
            txtEmail.ControlStyle.CssClass = "";
        }

        #endregion

        #region Spouse Details
        //Spouse Name
        if (rfvSpouseName.Enabled && rfvSpouseName.ValidationGroup == strValidationGroup)
        {
            rfvSpouseName.Validate();
            if (rfvSpouseName.IsValid == false)
            {
                txtSpouseName.ControlStyle.CssClass = "validationError";
            }
            else
            {
                txtSpouseName.ControlStyle.CssClass = "";
            }
        }
        else
        {
            txtSpouseName.ControlStyle.CssClass = "";
        }

        if (revSpouseName.Enabled && revSpouseName.ValidationGroup == strValidationGroup)
        {
            if (rfvSpouseName.IsValid)
            {
                revSpouseName.Validate();
                if (revSpouseName.IsValid == false)
                {
                    txtSpouseName.ControlStyle.CssClass = "validationError";
                }
                else
                {
                    txtSpouseName.ControlStyle.CssClass = "";
                }
            }
        }
        else
        {
            txtSpouseName.ControlStyle.CssClass = "";
        }

        ddlSpouseGender.ChangeValidationEffectServerSide(strValidationGroup);
        ddlSpouseIdNumber.ChangeValidationEffectServerSide(strValidationGroup);
        //ddlSpouseNationality.ChangeValidationEffectServerSide(strValidationGroup);
        //ddlSpouseRelationship.ChangeValidationEffectServerSide(strValidationGroup);

        #endregion

        #region Child Details

        //Child 1
        if (rfvChildName1.Enabled && rfvChildName1.ValidationGroup == strValidationGroup)
        {
            rfvChildName1.Validate();
            if (rfvChildName1.IsValid == false)
            {
                txtChildName1.ControlStyle.CssClass = "validationError";
            }
            else
            {
                txtChildName1.ControlStyle.CssClass = "";
            }
        }
        else
        {
            txtChildName1.ControlStyle.CssClass = "";
        }

        if (revChildName1.Enabled && revChildName1.ValidationGroup == strValidationGroup)
        {
            if (rfvChildName1.IsValid)
            {
                revChildName1.Validate();
                if (revChildName1.IsValid == false)
                {
                    txtChildName1.ControlStyle.CssClass = "validationError";
                }
                else
                {
                    txtChildName1.ControlStyle.CssClass = "";
                }
            }
        }
        else
        {
            txtChildName1.ControlStyle.CssClass = "";
        }

        ddlChildDOB1.ChangeValidationEffectServerSide(strValidationGroup);
        ddlChildGender1.ChangeValidationEffectServerSide(strValidationGroup);
        ddlChildIdNumber1.ChangeValidationEffectServerSide(strValidationGroup);
        //ddlChildNationality1.ChangeValidationEffectServerSide(strValidationGroup);
        //ddlChildRelationship1.ChangeValidationEffectServerSide(strValidationGroup);

        //Child 2
        if (rfvChildName2.Enabled && rfvChildName2.ValidationGroup == strValidationGroup)
        {
            rfvChildName2.Validate();
            if (rfvChildName2.IsValid == false)
            {
                txtChildName2.ControlStyle.CssClass = "validationError";
            }
            else
            {
                txtChildName2.ControlStyle.CssClass = "";
            }
        }
        else
        {
            txtChildName2.ControlStyle.CssClass = "";
        }

        if (revChildName2.Enabled && revChildName2.ValidationGroup == strValidationGroup)
        {
            if (rfvChildName2.IsValid)
            {
                revChildName2.Validate();
                if (revChildName2.IsValid == false)
                {
                    txtChildName2.ControlStyle.CssClass = "validationError";
                }
                else
                {
                    txtChildName2.ControlStyle.CssClass = "";
                }
            }
        }
        else
        {
            txtChildName2.ControlStyle.CssClass = "";
        }

        ddlChildDOB2.ChangeValidationEffectServerSide(strValidationGroup);
        ddlChildGender2.ChangeValidationEffectServerSide(strValidationGroup);
        ddlChildIdNumber2.ChangeValidationEffectServerSide(strValidationGroup);
        //ddlChildNationality2.ChangeValidationEffectServerSide(strValidationGroup);
        //ddlChildRelationship2.ChangeValidationEffectServerSide(strValidationGroup);

        //Child 3
        if (rfvChildName3.Enabled && rfvChildName3.ValidationGroup == strValidationGroup)
        {
            rfvChildName3.Validate();
            if (rfvChildName3.IsValid == false)
            {
                txtChildName3.ControlStyle.CssClass = "validationError";
            }
            else
            {
                txtChildName3.ControlStyle.CssClass = "";
            }
        }
        else
        {
            txtChildName3.ControlStyle.CssClass = "";
        }

        if (revChildName3.Enabled && revChildName3.ValidationGroup == strValidationGroup)
        {
            if (rfvChildName3.IsValid)
            {
                revChildName3.Validate();
                if (revChildName3.IsValid == false)
                {
                    txtChildName3.ControlStyle.CssClass = "validationError";
                }
                else
                {
                    txtChildName3.ControlStyle.CssClass = "";
                }
            }
        }
        else
        {
            txtChildName3.ControlStyle.CssClass = "";
        }

        ddlChildDOB3.ChangeValidationEffectServerSide(strValidationGroup);
        ddlChildGender3.ChangeValidationEffectServerSide(strValidationGroup);
        ddlChildIdNumber3.ChangeValidationEffectServerSide(strValidationGroup);
        //ddlChildNationality3.ChangeValidationEffectServerSide(strValidationGroup);
        //ddlChildRelationship3.ChangeValidationEffectServerSide(strValidationGroup);

        //Child 4
        if (rfvChildName4.Enabled && rfvChildName4.ValidationGroup == strValidationGroup)
        {
            rfvChildName4.Validate();
            if (rfvChildName4.IsValid == false)
            {
                txtChildName4.ControlStyle.CssClass = "validationError";
            }
            else
            {
                txtChildName4.ControlStyle.CssClass = "";
            }
        }
        else
        {
            txtChildName4.ControlStyle.CssClass = "";
        }

        if (revChildName4.Enabled && revChildName4.ValidationGroup == strValidationGroup)
        {
            if (rfvChildName4.IsValid)
            {
                revChildName4.Validate();
                if (revChildName4.IsValid == false)
                {
                    txtChildName4.ControlStyle.CssClass = "validationError";
                }
                else
                {
                    txtChildName4.ControlStyle.CssClass = "";
                }
            }
        }
        else
        {
            txtChildName4.ControlStyle.CssClass = "";
        }

        ddlChildDOB4.ChangeValidationEffectServerSide(strValidationGroup);
        ddlChildGender4.ChangeValidationEffectServerSide(strValidationGroup);
        ddlChildIdNumber4.ChangeValidationEffectServerSide(strValidationGroup);
        //ddlChildNationality4.ChangeValidationEffectServerSide(strValidationGroup);
        //ddlChildRelationship4.ChangeValidationEffectServerSide(strValidationGroup);

        //Child 5
        if (rfvChildName5.Enabled && rfvChildName5.ValidationGroup == strValidationGroup)
        {
            rfvChildName5.Validate();
            if (rfvChildName5.IsValid == false)
            {
                txtChildName5.ControlStyle.CssClass = "validationError";
            }
            else
            {
                txtChildName5.ControlStyle.CssClass = "";
            }
        }
        else
        {
            txtChildName5.ControlStyle.CssClass = "";
        }

        if (revChildName5.Enabled && revChildName5.ValidationGroup == strValidationGroup)
        {
            if (rfvChildName5.IsValid)
            {
                revChildName5.Validate();
                if (revChildName5.IsValid == false)
                {
                    txtChildName5.ControlStyle.CssClass = "validationError";
                }
                else
                {
                    txtChildName5.ControlStyle.CssClass = "";
                }
            }
        }
        else
        {
            txtChildName5.ControlStyle.CssClass = "";
        }

        ddlChildDOB5.ChangeValidationEffectServerSide(strValidationGroup);
        ddlChildGender5.ChangeValidationEffectServerSide(strValidationGroup);
        ddlChildIdNumber5.ChangeValidationEffectServerSide(strValidationGroup);
        //ddlChildNationality5.ChangeValidationEffectServerSide(strValidationGroup);
        //ddlChildRelationship5.ChangeValidationEffectServerSide(strValidationGroup);

        #endregion

        #region Other Info

      

        //HazadousHobby 
        if (rfvHazadousHobby.Enabled && rfvHazadousHobby.ValidationGroup == strValidationGroup)
        {
            rfvHazadousHobby.Validate();
            if (rfvHazadousHobby.IsValid == false)
            {
                lblYesHazadousHobby.ControlStyle.CssClass = "validationError";
                lblNoHazadousHobby.ControlStyle.CssClass = "validationError";
            }
            else
            {
                lblYesHazadousHobby.ControlStyle.CssClass = "";
                lblNoHazadousHobby.ControlStyle.CssClass = "";
            }
        }
        else
        {
            lblYesHazadousHobby.ControlStyle.CssClass = "";
            lblNoHazadousHobby.ControlStyle.CssClass = "";
        }
        //Hazadous Hobby Reason
        if (rfvHazadousHobbyReason.Enabled && rfvHazadousHobbyReason.ValidationGroup == strValidationGroup)
        {
            rfvHazadousHobbyReason.Validate();
            if (rfvHazadousHobbyReason.IsValid == false)
            {
                txtHazadousHobbyReason.ControlStyle.CssClass = "validationError";
            }
            else
            {
                txtHazadousHobbyReason.ControlStyle.CssClass = "";
            }
        }
        else
        {
            txtHazadousHobbyReason.ControlStyle.CssClass = "";
        }

        //Physicaldefect
        if (rfvPhysicaldefect.Enabled && rfvPhysicaldefect.ValidationGroup == strValidationGroup)
        {
            rfvPhysicaldefect.Validate();
            if (rfvPhysicaldefect.IsValid == false)
            {
                lblYesPhysicaldefect.ControlStyle.CssClass = "validationError";
                lblNoPhysicaldefect.ControlStyle.CssClass = "validationError";
            }
            else
            {
                lblYesPhysicaldefect.ControlStyle.CssClass = "";
                lblNoPhysicaldefect.ControlStyle.CssClass = "";
            }
        }
        else
        {
            lblYesPhysicaldefect.ControlStyle.CssClass = "";
            lblNoPhysicaldefect.ControlStyle.CssClass = "";
        }
        //Physicaldefect Reason
        if (rfvPhysicaldefectReason.Enabled && rfvPhysicaldefectReason.ValidationGroup == strValidationGroup)
        {
            rfvPhysicaldefectReason.Validate();
            if (rfvPhysicaldefectReason.IsValid == false)
            {
                txtPhysicaldefectReason.ControlStyle.CssClass = "validationError";
            }
            else
            {
                txtPhysicaldefectReason.ControlStyle.CssClass = "";
            }
        }
        else
        {
            txtPhysicaldefectReason.ControlStyle.CssClass = "";
        }     

        //Insurance Cancelled
        if (rfvInsuranceCancelled.Enabled && rfvInsuranceCancelled.ValidationGroup == strValidationGroup)
        {
            rfvInsuranceCancelled.Validate();
            if (rfvInsuranceCancelled.IsValid == false)
            {
                lblYesInsuranceCancelled.ControlStyle.CssClass = "validationError";
                lblNoInsuranceCancelled.ControlStyle.CssClass = "validationError";
            }
            else
            {
                lblYesInsuranceCancelled.ControlStyle.CssClass = "";
                lblNoInsuranceCancelled.ControlStyle.CssClass = "";
            }
        }
        else
        {
            lblYesInsuranceCancelled.ControlStyle.CssClass = "";
            lblNoInsuranceCancelled.ControlStyle.CssClass = "";
        }
        //InsuranceCancelled Reson
        if (rfvInsuranceCancelledReason.Enabled && rfvInsuranceCancelledReason.ValidationGroup == strValidationGroup)
        {
            rfvInsuranceCancelledReason.Validate();
            if (rfvInsuranceCancelledReason.IsValid == false)
            {
                txtInsuranceCancelledReason.ControlStyle.CssClass = "validationError";
            }
            else
            {
                txtInsuranceCancelledReason.ControlStyle.CssClass = "";
            }
        }
        else
        {
            txtInsuranceCancelledReason.ControlStyle.CssClass = "";
        }

        #endregion


    }

    protected void Check2NRICValid(object sender, ServerValidateEventArgs args)
    {
        string _appID = ddlIdNumber.GetIdNumber();
        string _spouseID = ddlSpouseIdNumber.GetIdNumber();

        if (_appID == _spouseID)
        {
            args.IsValid = false;
        }
        else
        {
            args.IsValid = true;
        }

    }

    private void EnableChildPanels()
    {
        if (txtIsCover.Text.Trim() == "INDSP" || txtIsCover.Text.Trim() == "INDSPCHD")
        {
            pnlSpouse.Visible = true;
            rfvSpouseName.Enabled = true;
            revSpouseName.Enabled = true;
            //csvNRIC.Enabled = true;
            //ddlSpouseGender.IsEnableValidation(true);
            ddlSpouseIdNumber.IsEnableValidation(true);
            //ddlSpouseNationality.IsEnableValidation(true);
            //ddlSpouseRelationship.IsEnableValidation(true);            
        }
        else
        {
            pnlSpouse.Visible = false;
            rfvSpouseName.Enabled = false;
            revSpouseName.Enabled = false;
            //csvNRIC.Enabled = false;
            //ddlSpouseGender.IsEnableValidation(false);
            ddlSpouseIdNumber.IsEnableValidation(false);
            //ddlSpouseNationality.IsEnableValidation(false);
            //ddlSpouseRelationship.IsEnableValidation(false);
        }
        if (txtCHCount.Text.Trim() == "0")
        {
            pnlChildParticulars.Visible = false;
            pnlChild1.Visible = false;
            pnlChild2.Visible = false;
            pnlChild3.Visible = false;
            pnlChild4.Visible = false;
            pnlChild5.Visible = false;

            ValidateChild1(false);
            ValidateChild2(false);
            ValidateChild3(false);
            ValidateChild4(false);
            ValidateChild5(false);
        }
        else if (txtCHCount.Text.Trim() == "1")
        {
            pnlChildParticulars.Visible = true;
            pnlChild1.Visible = true;
            pnlChild2.Visible = false;
            pnlChild3.Visible = false;
            pnlChild4.Visible = false;
            pnlChild5.Visible = false;

            ValidateChild1(true);
            ValidateChild2(false);
            ValidateChild3(false);
            ValidateChild4(false);
            ValidateChild5(false);
        }
        else if (txtCHCount.Text.Trim() == "2")
        {
            pnlChildParticulars.Visible = true;
            pnlChild1.Visible = true;
            pnlChild2.Visible = true;
            pnlChild3.Visible = false;
            pnlChild4.Visible = false;
            pnlChild5.Visible = false;

            ValidateChild1(true);
            ValidateChild2(true);
            ValidateChild3(false);
            ValidateChild4(false);
            ValidateChild5(false);
        }
        else if (txtCHCount.Text.Trim() == "3")
        {
            pnlChildParticulars.Visible = true;
            pnlChild1.Visible = true;
            pnlChild2.Visible = true;
            pnlChild3.Visible = true;
            pnlChild4.Visible = false;
            pnlChild5.Visible = false;

            ValidateChild1(true);
            ValidateChild2(true);
            ValidateChild3(true);
            ValidateChild4(false);
            ValidateChild5(false);
        }
        else if (txtCHCount.Text.Trim() == "4")
        {
            pnlChildParticulars.Visible = true;
            pnlChild1.Visible = true;
            pnlChild2.Visible = true;
            pnlChild3.Visible = true;
            pnlChild4.Visible = true;
            pnlChild5.Visible = false;

            ValidateChild1(true);
            ValidateChild2(true);
            ValidateChild3(true);
            ValidateChild4(true);
            ValidateChild5(false);
        }
        else if (txtCHCount.Text.Trim() == "5")
        {
            pnlChildParticulars.Visible = true;
            pnlChild1.Visible = true;
            pnlChild2.Visible = true;
            pnlChild3.Visible = true;
            pnlChild4.Visible = true;
            pnlChild5.Visible = true;

            ValidateChild1(true);
            ValidateChild2(true);
            ValidateChild3(true);
            ValidateChild4(true);
            ValidateChild5(true);
        }
    }

    private void ValidateChild1(bool OnOff)
    {
        rfvChildName1.Enabled = OnOff;
        revChildName1.Enabled = OnOff;
        ddlChildDOB1.IsEnableValidation(OnOff);
        ddlChildGender1.IsEnableValidation(OnOff);
        ddlChildIdNumber1.IsEnableValidation(OnOff);
        //ddlChildNationality1.IsEnableValidation(OnOff);
        //ddlChildRelationship1.IsEnableValidation(OnOff);
    }

    private void ValidateChild2(bool OnOff)
    {
        rfvChildName2.Enabled = OnOff;
        revChildName2.Enabled = OnOff;
        ddlChildDOB2.IsEnableValidation(OnOff);
        ddlChildGender2.IsEnableValidation(OnOff);
        ddlChildIdNumber2.IsEnableValidation(OnOff);
        //ddlChildNationality2.IsEnableValidation(OnOff);
        //ddlChildRelationship2.IsEnableValidation(OnOff);
    }

    private void ValidateChild3(bool OnOff)
    {
        rfvChildName3.Enabled = OnOff;
        revChildName3.Enabled = OnOff;
        ddlChildDOB3.IsEnableValidation(OnOff);
        ddlChildGender3.IsEnableValidation(OnOff);
        ddlChildIdNumber3.IsEnableValidation(OnOff);
        //ddlChildNationality3.IsEnableValidation(OnOff);
        //ddlChildRelationship3.IsEnableValidation(OnOff);
    }

    private void ValidateChild4(bool OnOff)
    {
        rfvChildName4.Enabled = OnOff;
        revChildName4.Enabled = OnOff;
        ddlChildDOB4.IsEnableValidation(OnOff);
        ddlChildGender4.IsEnableValidation(OnOff);
        ddlChildIdNumber4.IsEnableValidation(OnOff);
        //ddlChildNationality4.IsEnableValidation(OnOff);
        //ddlChildRelationship4.IsEnableValidation(OnOff);
    }

    private void ValidateChild5(bool OnOff)
    {
        rfvChildName5.Enabled = OnOff;
        revChildName5.Enabled = OnOff;
        ddlChildDOB5.IsEnableValidation(OnOff);
        ddlChildGender5.IsEnableValidation(OnOff);
        ddlChildIdNumber5.IsEnableValidation(OnOff);
        //ddlChildNationality5.IsEnableValidation(OnOff);
        //ddlChildRelationship5.IsEnableValidation(OnOff);
    }

    private void ShowUserDetails()
    {
        //hplEditProfile.Visible = true;
        CE.User.Profile _profile = new CE.User.Profile();
        CE.User.ProfileDB _profiledb = new ProfileDB();
        CE.User.Contact _contact = new Contact();
        CE.User.ContactDB _contactdb = new ContactDB();

        Int64 UserId = Convert.ToInt64(Session[General.UserId].ToString());
        _profile = _profiledb.GetProfile(UserId);
        if (_profile != null)
        {
            txtName.Text = _profile.FirstName + " " + _profile.SurName;

            if (_profile.IDNo.Length == 9)
            {
                ddlIdNumber.Prefix = _profile.IDNo[0].ToString();
                ddlIdNumber.Postfix = _profile.IDNo[8].ToString();
                ddlIdNumber.IDNumber = _profile.IDNo.Substring(1, 7);
            }

            if (_profile.Gender.ToString() != "")
            {
                ddlGender.Gender = _profile.Gender.ToString();
            }

            if (_profile.Nationality != "")
            {
                ddlNationality.Nationality = _profile.Nationality.ToString();
            }

            _contact = _contactdb.GetContact(UserId);
            if (_contact != null)
            {
                txtMobileNo.PhoneNo = _contact.Mobile;
                txtOfficePhoneNo.PhoneNo = _contact.OfficePhone;
                txtEmail.Text = _contact.Email.ToString();

            }

            _profile = null;
            _profiledb = null;
            _contact = null;
            _contactdb = null;
        }


    }

    private void GetPostCode()
    {
        rfvPostCode.Validate();
        revPostCode.Validate();
        if (rfvPostCode.IsValid && revPostCode.IsValid)
        {
            txtPostCode.ControlStyle.CssClass = "";
            txtAddress.ControlStyle.CssClass = "";
            MyLocation _myLoc = new MyLocation();
            //string _strAddress = _myLoc.GetAddressByPostCode(txtPostCode.Text);
            //if (_strAddress != null && _strAddress != string.Empty)
            //{
            //    if (_strAddress.ToLower().Contains("invalid api"))
            //    {
            //        txtAddress.Text = "Address can't be retrieved. Please type your address detail here.";
            //    }
            //    else
            //    {
            //        txtAddress.Text = _strAddress;
            //    }
            //}
            //else
            //{
            //    txtAddress.Text = "Address is not found.";
            //}

            System.Data.DataSet _ds = _myLoc.GetAddressByPostCodeDataSet(txtPostCode.Text);
            ddlAddressList.Items.Clear();
            string _lstValue;
            string _lstText;
            int _rowCount = 0;

            if (_ds != null)
            {
                if (_ds.Tables.Count > 0)
                {
                    foreach (System.Data.DataTable _dt in _ds.Tables)
                    {
                        if (_dt.Rows.Count > 0 && _dt.Columns.Count >= 2)
                        {
                            foreach (System.Data.DataRow _dr in _dt.Rows)
                            {
                                //lblAddress2.Text += _dr["t"].ToString() + "<br />";
                                //lblAddress2.Text += _dr["a"].ToString() + "<br /><br />";
                                
                                if (_dr["t"] != null && _dr["a"] != null)
                                {
                                    _lstValue = _dr["t"].ToString() + ", " + _dr["a"].ToString();
                                    _lstText = _dr["t"].ToString();
                                    ddlAddressList.Items.Add(new ListItem(_lstText, _lstValue));
                                    if (_rowCount == 0)
                                    {
                                        txtAddress.Text = _lstValue;
                                        //ibtPostCode.Enabled = false;
                                        txtAddress.ReadOnly = true;
                                    }

                                    _rowCount++;
                                }
                            }
                        }
                        else
                        {
                            txtAddress.Text = "Confirm postcode or enter manually.";
                            txtAddress.ReadOnly = false;
                            txtAddress.ControlStyle.CssClass = "validationError";
                        }
                    }
                }
                else
                {
                    txtAddress.Text = "Confirm postcode or enter manually.";
                    txtAddress.ReadOnly = false;
                    txtAddress.ControlStyle.CssClass = "validationError";
                }
            }
            else
            {
                txtAddress.Text = "Please type your address here.";
                txtAddress.ReadOnly = false;
                txtAddress.ControlStyle.CssClass = "validationError";
            }

            if (_rowCount > 1)
            {
                divAddressList.Visible = true;
            }
            else
            {
                divAddressList.Visible = false;

            }
        }
        else
        {
            txtPostCode.ControlStyle.CssClass = "validationError";
            ddlAddressList.Items.Clear();
            divAddressList.Visible = false;
            txtAddress.Text = "Invalid postcode.";
            txtAddress.ControlStyle.CssClass = "validationError";
        }
    }

    public string GetOrderNumber()
    {
        Int64 _orderserialno = 0;
        string _result, _serialno;
        _result = "";  _serialno = "";
        MyDatabase _db = new MyDatabase();
        string _firstno = CE.Global.General.GetUTCDateTime().Year + CE.Global.General.GetUTCDateTime().Month.ToString("00") + CE.Global.General.GetUTCDateTime().Day.ToString("00");

        if (Session[General.UserId] != null && Session[General.CarId] != null)
        {
            _PAId = Convert.ToInt64(Session[CE.Global.General.PAId].ToString());
            _UserId = Convert.ToInt64(Session[CE.Global.General.UserId].ToString());
        }
        else if (Request.Params["carid"] != null && Request.Params["customerid"] != null)
        {
            _PAId = Convert.ToInt64(lblPAId.Text);
            _UserId = Convert.ToInt64(lblCustomerId.Text);
        }


        _result = _firstno + _PAId.ToString("000000");
        string strSql = "SELECT TOP 1 OrderSerialNo FROM tblPAProposal_Etiqa WHERE OrderNo IS NOT NULL ORDER BY OrderSerialNo DESC";
        DataSet _dsResult = new DataSet();
        _dsResult = null;
        _dsResult = _db.GetDataSet(strSql);
        if (_dsResult != null && _dsResult.Tables[0].Rows.Count > 0)
        {
            _orderserialno = Convert.ToInt64(_dsResult.Tables[0].Rows[0][0].ToString());
            _orderserialno = _orderserialno + 1;
            _serialno = _orderserialno.ToString("000000");
        }
        else
        {
            _orderserialno = 1;
            _serialno = _orderserialno.ToString("000000");
        }

        _result += _serialno + "," + _orderserialno.ToString();
        return _result;
    }

}
